<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;

use App\CustHub\Model\ChRoomBroadcastSource;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

class ChRoomBroadcastSourceMapper extends AbstractMapper
{
    public function assignModel()
    {
        $this->model = ChRoomBroadcastSource::class;
    }

    public function handleSearch(Builder $query, array $params): Builder
    {
        $query->where('main_uid',$params['main_uid']);

        if(isset($params['wechat_type']) && filled($params['wechat_type'])){
            $query->where('wechat_type',$params['wechat_type']);
        }

        return $query;
    }

    public function handleOrder(Builder $query, ?array &$params = null): Builder
    {
        return $query->orderByDesc('created_at');
    }
}